package org.example.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.example.service.impl.CongtractServiceImpl;
import org.example.service.impl.ContractAdapterImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * ============================================================<br>
 * <p> ProjectName ：dianguanjiaexportdata </p>
 * <p> @author dongjianzhao </p>
 * <p> @date 2023/3/18 </p>
 * <p> @version ：1.0 </p>
 * ============================================================<br>
 * <p>
 * Contract 电管家合同数据爬取
 * </p>
 * ============================================================<br>
 */
@RestController
@RequestMapping("/contract")
public class ContractController {

    @Autowired
    private ContractAdapterImpl contractAdapter;

    @Autowired
    private CongtractServiceImpl congtractService;

    /**
     * lizheng  获取合同列表
     * @throws JsonProcessingException
     */
    @PostMapping("getContractList")
    public void getContractList() throws JsonProcessingException {
        congtractService.queryContractParameterList();
    }

    /**
     * 获取合同的详情
     * @throws JsonProcessingException
     */
    @PostMapping("contractInfo")
    public void contractInfo() throws JsonProcessingException {
        congtractService.contractInfo();
    }

    /**
     * 同步 那些只有变压器编码和序列号的信息
     */
    @RequestMapping(value="/updateByqBmXlh",method= RequestMethod.GET)
    public void updateByqBmXlh(){
        congtractService.updateByqBmXlh();
    }
    @RequestMapping(value="/adapter",method= RequestMethod.GET)
    public void adapter(){
        contractAdapter.adapter();
    }


    /**
     * 合同列表查询
     */
    //  private String queryContractParameterList="http://222.223.186.60:18020/energy-server/v1/restContractParameterController/queryContractParameterList";

  /* private  List<Map<String, Object>> getContractListMaps(int page) {

        Map<String,Object> param=new HashMap<>();
        param.put("ciCity","");
        param.put("pageFlag","true");
        param.put("currentPageNum",page);
        param.put("ctrtPage" ,"cons200");
        //页面容量
        String s= HttpUtils.httpPost(queryContractParameterList,param,cookie);
        JSONObject parse = (JSONObject) JSONObject.parse(s);
        JSONObject datas = (JSONObject) parse.get("data");
        JSONArray userList =(JSONArray)  datas.get("usersList");
        List<Map<String,Object>> list=new ArrayList<>();
        for (int i=0;i<userList.size();i++){
            JSONObject j= (JSONObject) userList.get(i);
            String ciId = (String) j.get("ciId");
            Map<String, Object> stringObjectMap =new HashMap<>();
            list.add(stringObjectMap);
        }
        return list;
    }*/
}
